package com.thread.thread.ThreadPool线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CachedThreadPoolTest {
	//缓存线程池,支持Integer.MaxValue个线程数，60秒后回收，加一个pool size+1，threadlocal变量也会在超过60秒之后消失
	public static ExecutorService executorService= Executors.newCachedThreadPool();

	public static void main(String[] args) {
		System.out.println(executorService);
		ThreadLocal<String> stringThreadLocal=new ThreadLocal<>();
		executorService.submit(new Runnable() {
			@Override
			public void run() {
				stringThreadLocal.set("菜菜");
				System.out.println(Thread.currentThread().getName());
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
		System.out.println(executorService);
		try {
			Thread.sleep(65111);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		executorService.submit(()->{

			System.out.println(Thread.currentThread().getName()+"--"+stringThreadLocal.get());
		});

		System.out.println(executorService);
	}
}
